# -*- coding:utf-8 -*-#
"""
作者：王凯
日期：2024年09月08日
时间：16时04分
"""
from selenium import webdriver
from selenium.webdriver.common.by import By
from ocr import ocr_img
import time

wd = webdriver.Edge()  # Edge浏览器驱动路径
wd.implicitly_wait(1)

wd.get(r"https://jxfzjsxy.cn/")  # 打开网址(抚州职业技术学院教学管理系统)
time.sleep(0.5)
student_id = "2023032347"
password = "123456"

def close_window():
    """
    关闭浏览器窗口
    :return:
    """
    wd.quit()
    exit()  # 退出程序


def get_ID(value):
    return wd.find_element(By.ID, value)


def get_XPATH(value):
    return wd.find_element(By.XPATH, value)




def login1():
    # 输入学号和密码
    element1 = get_ID("paramUsername")
    element1.send_keys(student_id)
    element2 = get_ID("paramPassword")
    element2.send_keys(password)


def identify():
    path = "code.png"
    element5 = get_XPATH('//*[@id="verifyImage"]')
    element5.screenshot(path)

    result = ocr_img(path)
    element3 = get_ID("verifyCode")
    element3.send_keys(result)
    time.sleep(0.5)


def login2():
    element4 = get_ID("btnSubmit")
    element4.click()
    time.sleep(0.5)


def find_score():
    try:
        try:
            element6 = get_XPATH('//*[@id="a_c4dcb63076e8efe26b4c3e80b2d06af3"]')
            element6.click()
            time.sleep(0.5)

            element7 = get_XPATH('//*[@id="menu"]/div[3]/div[2]')
            element7.click()
            time.sleep(0.5)
            iframe = get_ID("menuFrame")
            wd.switch_to.frame(iframe)
            element8 = get_XPATH('/html/body/div[1]/form/div/div[1]/div/input[3]')
            element8.click()
            time.sleep(10)
        except:
            print(f"{student_id}查找成绩失败")
    except:
        print(f"{student_id}登入失败，请检查学号和密码是否正确")

def main():
    print(f"{student_id}开始登入")
    login1()
    identify()
    login2()
    find_score()

